/*
 * James Milewski
*/
package test;

import server.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

// add the j connector to the library
// and change the DB.properites file
public class DBtest {
	public static void main(String [] args){
		DBManager db = DBManager.getInstance();
		try
		{
			//db.createGroup("jim","group");
			// not using this anymore
			//db.initializeBuddyList("jim", "buddy","group");//line 318 of DBManager.java
			// this adds to pending members if buddy doesn't exist in another group
			//db.addBuddyToGroup("jim", "buddy", "group");
			// check again; still adding 'buddy' to pendingmembers
			//db.createGroup("jim", "group2");
			//db.addBuddyToGroup("jim", "buddy","group2");
			//db.confirmBuddyToGroup("buddy", "jim", "group");
			BuddyList bl = db.getBuddyList("jim");
			Iterator<Group> g = bl.getGroups();
			while(g.hasNext()){
				Group group = g.next();
				Iterator<Person> p = group.getMembers();
				while(p.hasNext()){
					Person person = p.next();
					System.out.println(person.getUsername());
				}
			}
			//db.deleteBuddyFromGroup("jim", "buddy","group"); this works
			// test preferences working
			
			Preferences p = new Preferences();
			p.setUsername("jim"); p.setTimeAwayMode(1222222); p.setSound(true);
			p.setSortCriteria(Preferences.SortBy.GROUP); p.setIcon(false);
			p.setGrouped(false); p.setShowOffline(false); 
			p.setConvWindow(Preferences.ConversationWindow.TABBED);
			p.setDefaultPath("someOtherString"); p.setHistoryDays(5);
			db.storePreferences("jim", p);
			System.out.println();
			Preferences pp = db.getPreferences("jim");
			System.out.println("time away mode"+pp.getTimeAwayMode());
			System.out.println("testing enum "+pp.getConvWindow());
			System.out.println("path "+pp.getDefaultPath());
			
			//db.addOfflineMessage("jim","jim","jims offline message");
			//db.addOfflineMessage("jim","jim","jim message 2");
			//db.removeOfflineMessages("jim");
			Iterator<String> offMessages = db.getOfflineMessages("jim","jim");
			while(offMessages.hasNext()){
				String message = offMessages.next();
				System.out.println(message);
			}
			Iterator<String> offAuthors = db.getOfflineMessageAuthors("jim");
			while(offAuthors.hasNext()){
				System.out.println(offAuthors.next());
			}
			
		}
		catch(Exception e){
			System.out.println("Some excetpion "+ e.getMessage());
		}
	}
}

